/**
 * 
 */



$(function(){
	//////////////--------------删除留言--------------------/////////////////
	var $itemdiv_commentdiv_hidden = $("div[class='itemdiv commentdiv hidden']");
	var $delete = $itemdiv_commentdiv_hidden.find("i.delete");
	
	$delete.click(function(){
		var $leaving_msgs = $(this).parents("[class='itemdiv commentdiv']");
		var leaving_id = $leaving_msgs[0].id;
		
		$.post("Delete_leaving_msgs",{leaving_id:leaving_id},function(data,status){
			if(data.result==true){
				$leaving_msgs.remove();
			}else{
				alert("操作失败");
			}
		},"json");
	});
	
	
	//////////////////-----------------删除留言的人及其留言-------------/////////////////
	var $delete_user_msgs = $("a.delete_user_msgs");
	$delete_user_msgs.click(function(){
		var delete_leaving_user_account = $(this).parents("div[class='itemdiv memberdiv']")[0].id;
		
		$.post("Delete_leaving_user_msg",{delete_leaving_user_account:delete_leaving_user_account},function(data,status){
			if(data.result==true){
				//成功删除
				window.location.reload();
			}else{
				alert("数据出错");
			}
		},"json");
		
		
	});
	
	///////////////////------------------回复留言---------------------///////////////
	//回复留言
	var $reply = $("a.reply");
	$reply.click(function(){
		var receive_user_account = $(this).parents("div[class='itemdiv memberdiv']")[0].id;
		//alert(receive_user_account);
		x0p({
			title: '输入您的留言',
		    text: null,
		    width: "90%",
		    height: "50%",
		    type: "input",
		    inputType: "text",
		    buttons: [
		              {
		                  type: 'cancel',
		                  text: '取消'
		              },
		              {
		                  type: 'ok',
		                  text: '确认'
		              }
		          ],
		},function(button, text){
			if(button == 'ok') {
				if(text!=""&&text!=null){
					$.post("leaving_msg_to_attention",{receive_user_account:receive_user_account,leaving_content:text},function(data,status){
						if(data.result==true){
							//window.location.reload();
							x0p('提示',"回复已发送", 
					                'ok', false);
						}else{
							alert("留言失败");
						}
					},"json");
					
				}else{
					 x0p('提示',"输入不能为空", 
				                'error', false);
				}
	        }
	        if(button == 'cancel') {
	           
	        }
		});
	});
	
	
	
	
	
});








$(function(){
	var $itemdiv_commentdiv_hidden = $("div[class='itemdiv commentdiv hidden']");
	
	
	///////////////---------------------获取所有留言-----------------------/////////////
	$.get("leaving_messages",function(data,status){    
		if(data.result==true){
			for(i=0;i<data.my_leaving_Array.length;i++){
				var $leaving_msgs = $itemdiv_commentdiv_hidden.clone(true);
				$leaving_msgs[0].id = data.my_leaving_Array[i].leaving_id;
				if(data.my_leaving_Array[i].user_photo_path!=""&&data.my_leaving_Array[i].user_photo_path!=null){
					$leaving_msgs.find("div.leaving_msgs_user_photo").children("img")[0].src = data.my_leaving_Array[i].user_photo_path;
				}else{
					$leaving_msgs.find("div.leaving_msgs_user_photo").children("img")[0].src = "images/no_photo.jpg";
				}
				
				$leaving_msgs.find("div.leaving_msgs_user_name").children("a").html(data.my_leaving_Array[i].user_nickname);
				$leaving_msgs.find("div.leaving_msgs_time").children("span").html(data.my_leaving_Array[i].leaving_date);
				$leaving_msgs.find("div.leaving_msgs_text").children("span").html(data.my_leaving_Array[i].leaving_content);
				
				$leaving_msgs.removeClass("hidden");
				$leaving_msgs.insertAfter($itemdiv_commentdiv_hidden);
				
			}
		}
	},"json");
	
	
	////////////////////////----------------获取莫一个人的留言---------------///////////////////
	
	var $itemdiv_memberdiv_user = $("div[class='itemdiv memberdiv hidden']");
	var $send_user = $itemdiv_memberdiv_user.find("div.name").children("a");
	
	$send_user.click(function(){
		var send_user = $(this).parents("div[class='itemdiv memberdiv']")[0].id;
		$.post("leaving_messages",{send_user:send_user},function(data,status){
			if(data.result==true){
				$itemdiv_commentdiv_hidden.siblings().remove();
				for(i=0;i<data.my_leaving_Array.length;i++){
					var $leaving_msgs = $itemdiv_commentdiv_hidden.clone(true);
					$leaving_msgs[0].id = data.my_leaving_Array[i].leaving_id;
					if(data.my_leaving_Array[i].user_photo_path!=""&&data.my_leaving_Array[i].user_photo_path!=null){
						$leaving_msgs.find("div.leaving_msgs_user_photo").children("img")[0].src = data.my_leaving_Array[i].user_photo_path;
					}else{
						$leaving_msgs.find("div.leaving_msgs_user_photo").children("img")[0].src = "images/no_photo.jpg";
					}
					
					$leaving_msgs.find("div.leaving_msgs_user_name").children("a").html(data.my_leaving_Array[i].user_nickname);
					$leaving_msgs.find("div.leaving_msgs_time").children("span").html(data.my_leaving_Array[i].leaving_date);
					$leaving_msgs.find("div.leaving_msgs_text").children("span").html(data.my_leaving_Array[i].leaving_content);
					
					$leaving_msgs.removeClass("hidden");
					$leaving_msgs.insertAfter($itemdiv_commentdiv_hidden);
				}
			}else{
				alert("数据出错");
			}
			
		},"json");
		
	});
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
});

















$(function(){
	/////////////////////////------------------获取留言的人-------------------////////////////////
	var $itemdiv_memberdiv_user = $("div[class='itemdiv memberdiv hidden']");
	$.get("leaving_messages_user",function(data,status){
		if(data.result==true){
			for(i=0;i<data.my_leaving_user.length;i++){
				var $leaving_user = $itemdiv_memberdiv_user.clone(true);
				
				$leaving_user[0].id=data.my_leaving_user[i].user_account;
				if(data.my_leaving_user[i].user_photo_path!=""&&data.my_leaving_user[i].user_photo_path!=null){
				    $leaving_user.find("div.user").children("img")[0].src = data.my_leaving_user[i].user_photo_path;
				}else{
					$leaving_user.find("div.user").children("img")[0].src = "images/no_photo.jpg";
				}
				
				$leaving_user.find("div.name").children("a").html(data.my_leaving_user[i].user_nickname);
				
				$leaving_user.removeClass("hidden");
				$leaving_user.insertAfter($itemdiv_memberdiv_user);
				
			}
			
		}else{
			alert("请求数据失败");
		}
	},"json");
	
	
	
	
});














